
<div class="page-content" id="box1">
            <h1 class = "postTitle">
               linux端口开放指定端口的两种方法
            </h1>
            <div class="clear"></div>
                    <p>重要的事情说三遍,强烈建议使用第二种方法!第二种方法!第二!;</p>
                    <p>开放端口的方法：</p>
                    <p>方法一：命令行方式<br>
                        &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;1. 开放端口命令： /sbin/iptables -I INPUT -p tcp --dport 8080 -j ACCEPT<br>
                        &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;2.保存：/etc/rc.d/init.d/iptables save<br>
                        &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;3.重启服务：/etc/init.d/iptables restart<br>
                        &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;4.查看端口是否开放：/sbin/iptables -L -n<br>
                        &nbsp; &nbsp;&nbsp;</p>
                    <p >&nbsp;方法二：直接编辑/etc/sysconfig/iptables文件<br>
                        &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;1.编辑/etc/sysconfig/iptables文件：vi /etc/sysconfig/iptables<br>
                        &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;加入内容并保存：-A RH-Firewall-1-INPUT -m state --state NEW -m tcp -p tcp --dport 8080 -j ACCEPT<br>
                        &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;2.重启服务：/etc/init.d/iptables restart<br>
                        &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;3.查看端口是否开放：/sbin/iptables -L -n<br>
                    </p>
                    <p>但是我用方法一一直保存不上，查阅网上发现直接修改文件不需要iptables save，重启下iptables
                        重新加载下配置。iptables save
                        是将当前的iptables写入到/etc/sysconfig/iptables。我不save直接restart也不行，所以还是方法二吧</p>
                    <p><br>
                    </p>
                    <p>

                        查询端口是否有进程守护用如下命令grep对应端口，如80为端口号<br>
                        例：netstat -nalp|grep 80</p></div><div id="MySignature"></div>
</div>
<link rel="stylesheet" href="../css/mycss.css" />
<script src="js/jquery.min.js"></script>